/*
 * To change this temp

 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
 throw new UnsupportedOperationException("Not supported yet.");
 }
 }
 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
 throw new UnsupportedOperationException("Not supported yet.");
 }
 }ate, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InsertDiag.java
 *
 * Created on 11-ago-2011, 21.12.36
 */
package agenda;

import agenda.entityes.AgeEntry;
import agenda.entityes.TelNumber;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.event.MouseInputAdapter;

/**
 *
 * @author emanuele
 */
public class InsertDiag extends javax.swing.JDialog {
   /*
    * netbeans rompeva i coglioni ,e gli ho detto di aggiungere sto coso per farlo stare zitto
    */
   private static final long serialVersionUID = 1L;

   /*
    * tabella usata per inserire e rmuovere i numeri
    */
   private NumTable nt = new NumTable();
   // riferimento all'entry da modificare o da visionare
   AgeEntry entry;
   // lista delle entry della rubrica appartenenti al database
   List<AgeEntry> list;
   /**
    * modalità di scrittura abilitata
    */
   private boolean writeEnabled;
   private boolean editMode = true;

   /**
    * Crea una nuova istanza della classe insert dialog
    *
    * @param parent finestra genitore del dialogo di inserimento
    * @param WE true se è abilitato l'inserimento o la modifica di una entry
    * @param ent se non null' è l'entry da modificare
    * @param list lista di entry coteute nel database
    */
   public InsertDiag(java.awt.Frame parent, boolean WE, AgeEntry ent, List<AgeEntry> list) {
      super(parent, true);
      initComponents();

      nt.setVisible(true);
      jScrollPane1.setViewportView(nt);
      nt.setRowHeight(20);
      nt.setFillsViewportHeight(true);


      this.list = list;


      entry = ent;
      writeEnabled = WE;

      nomeTF.setEditable(WE);
      cognomeTF.setEditable(WE);
      emailTF.setEditable(WE);
      assadd.setEnabled(WE);
      assrem.setEnabled(WE);
      numadd.setEnabled(WE);
      numrem.setEnabled(WE);
      nt.setEnabled(WE);
      // TODO impostare jtable 1 come non editable
      descArea.setEditable(WE);

      linksList.setModel(new DefaultListModel());

      addWindowListener(new WindowListener() {

         @Override
         public void windowOpened(WindowEvent e) {
         }

         @Override
         public void windowClosing(WindowEvent e) {
            editCanceled(null);
         }

         @Override
         public void windowClosed(WindowEvent e) {
         }

         @Override
         public void windowIconified(WindowEvent e) {
         }

         @Override
         public void windowDeiconified(WindowEvent e) {
         }

         @Override
         public void windowActivated(WindowEvent e) {
         }

         @Override
         public void windowDeactivated(WindowEvent e) {
         }
      });


      if (ent != null) {
         updateView(ent);
      }


      changeEntryType();

      /*
       * imposta i mouseListners per gestire il cambiamento di tipo Azienda-Persona
       * e fare in modo che l'interfaccia venga aggiornata.
       */
      aziendajRadioButton.addMouseListener(new MouseInputAdapter() {

         @Override
         public void mouseClicked(java.awt.event.MouseEvent evt) {
            changeEntryType();
         }

      });
      personajRadioButton.addMouseListener(new MouseInputAdapter() {

         @Override
         public void mouseClicked(java.awt.event.MouseEvent evt) {
            changeEntryType();
         }
      });

      pack();
   }

   /**
    * Funzione di utilit&agrave; per l'aggiornamento della vista. Inizializza tutti i campi con i valori contenuti nella
    * voce di agenda e. usata solo se il dialogo &egrave; usato per la visualizzazione di una voce
    *
    * @param e
    */
   private void updateView(AgeEntry e) {
      //seleziona persona o azienda
      if (e.getType() == AgeEntry.Type.Azienda) {
         aziendajRadioButton.setSelected(true);
      } else if (e.getType() == AgeEntry.Type.Persona) {
         personajRadioButton.setEnabled(true);
      }


      setNumbers(e.getNumbers());
      if (e.getType() == AgeEntry.Type.Persona) {
         nomeTF.setText(e.getName());
      }
      cognomeTF.setText(e.getSurname());
      emailTF.setText(e.getEmail());
      descArea.setText(e.getDesc());
      // aggiorna i link
      DefaultListModel lmodel = (DefaultListModel) linksList.getModel();
      lmodel.clear();
      for (AgeEntry s : e.getAssociations()) {
         lmodel.addElement(s);
      }
   }

   private void setNumbers(List<TelNumber> nums) {
      for (int i = 0; i < nt.getRowCount(); i++) {
         nt.delRow(i);
      }
      for (TelNumber n : nums) {
         Object[] arr = new Object[2];
         arr[0] = n.getType();
         arr[1] = n.num;
         nt.addRow(arr);
      }
   }

   /*
    * legge i valori dai vari componenti dell'interfaccia e li inserisce nella entry presente come membro di questa
    * classe.
    *
    * poi chiama in metodo validate() della classe Entry che ritorna true se tutto è andato a buon fine e false
    * altrimenti. se il metodo validate() restituisce false, questo metodo restituisce false.
    */
   private boolean applyChanges() {

      if (entry == null) {
         entry = new AgeEntry(getSelType());
      }

      entry.setName(nomeTF.getText().trim());
      entry.setSurname(cognomeTF.getText().trim());
      entry.setEmail(emailTF.getText().trim());
      entry.setDesc(descArea.getText().trim());

      // elimina tutti i numeri esistenti
      entry.getNumbers().clear();
      // riscrivi i numeri presenti nella tabella
      for (int i = 0; i < nt.getRowCount(); i++) {
         // prendi un numero
         TelNumber num = new TelNumber((TelNumber.Type) nt.getValueAt(i, 0), (String) nt.getValueAt(i, 1));
         // FIXME aggiungi solo se è valido
         entry.addNumber(num);
      }

      DefaultListModel lmodel = (DefaultListModel) linksList.getModel();
      // elimina tutti i link esistenti
      entry.clearAssociations();
      // riscrivi i numeri presenti nella lista
      for (int i = 0; i < lmodel.getSize(); i++) {
         AgeEntry e = (AgeEntry) lmodel.get(i);
         entry.addAssociation(e);
      }

      /*
       * verifica della validità dei dati
       */
      if (entry.validate()) {
         return true;
      }

      return false;

   }

   /**
    * Ritorna il tipo di entry selezionato.
    */
   private AgeEntry.Type getSelType() {
      return personajRadioButton.isSelected() ? AgeEntry.Type.Persona : aziendajRadioButton.isSelected() ? AgeEntry.Type.Azienda : null;
   }


      /**
    * Ritorna la voce di agenda che è stata inserita.
    *
    * @return la voce inserita , null se è stato annullato l'inserimento
    *
    */
   public AgeEntry getData() {
      setVisible(true);
      dispose();
      return entry;
   }

   /*
    * metodo interno che si occupa di cambiare il testo delle jLabel
    */
   private void changeEntryType() {
      if (personajRadioButton.isSelected()) {
         cognomeL.setText("Cognome");
         nameL.setVisible(true);
         nomeTF.setVisible(true);

      } else if (aziendajRadioButton.isSelected()) {
         cognomeL.setText("Nome");
         nameL.setVisible(false);
         nomeTF.setVisible(false);
      }

      pack();
   }



   /**
    * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
    * content of this method is always regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        aziendajRadioButton = new javax.swing.JRadioButton();
        personajRadioButton = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        descArea = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        cognomeL = new javax.swing.JLabel();
        cognomeTF = new javax.swing.JFormattedTextField();
        nameL = new javax.swing.JLabel();
        nomeTF = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        emailTF = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        numrem = new javax.swing.JButton();
        numadd = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        linksList = new javax.swing.JList();
        assrem = new javax.swing.JButton();
        assadd = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        confirmB = new javax.swing.JButton();
        cancelB = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Inserimento");
        setMinimumSize(new java.awt.Dimension(560, 340));
        setModal(true);
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(580, 340));
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.GridBagLayout());

        buttonGroup1.add(aziendajRadioButton);
        aziendajRadioButton.setSelected(true);
        aziendajRadioButton.setText("Azienda"); // NOI18N
        aziendajRadioButton.setName("aziendajRadioButton"); // NOI18N
        aziendajRadioButton.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        jPanel1.add(aziendajRadioButton, gridBagConstraints);

        buttonGroup1.add(personajRadioButton);
        personajRadioButton.setText("Persona"); // NOI18N
        personajRadioButton.setName("personajRadioButton"); // NOI18N
        personajRadioButton.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.1;
        jPanel1.add(personajRadioButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.3;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(jPanel1, gridBagConstraints);

        jScrollPane1.setName("jScrollPane4");
        jScrollPane1.setPreferredSize(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(jScrollPane1, gridBagConstraints);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        descArea.setColumns(20);
        descArea.setLineWrap(true);
        descArea.setRows(5);
        descArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        descArea.setName("descArea"); // NOI18N
        descArea.setPreferredSize(null);
        jScrollPane2.setViewportView(descArea);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(jScrollPane2, gridBagConstraints);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.GridBagLayout());

        cognomeL.setText("Cognome"); // NOI18N
        cognomeL.setName("cognomeL"); // NOI18N
        cognomeL.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        jPanel3.add(cognomeL, gridBagConstraints);

        cognomeTF.setName("cognomeTF"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.2;
        jPanel3.add(cognomeTF, gridBagConstraints);

        nameL.setText("Nome"); // NOI18N
        nameL.setName("nameL"); // NOI18N
        nameL.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0);
        jPanel3.add(nameL, gridBagConstraints);

        nomeTF.setName("nomeTF"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.2;
        jPanel3.add(nomeTF, gridBagConstraints);

        jLabel2.setText("e-mail"); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        jLabel2.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0);
        jPanel3.add(jLabel2, gridBagConstraints);

        emailTF.setName("emailTF"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.weighty = 0.1;
        jPanel3.add(emailTF, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(jPanel3, gridBagConstraints);

        jLabel1.setText("Note"); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(jLabel1, gridBagConstraints);

        numrem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/list_remove.png"))); // NOI18N
        numrem.setMargin(new java.awt.Insets(0, 0, 0, 0));
        numrem.setName("numrem"); // NOI18N
        numrem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                delNumber(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(numrem, gridBagConstraints);

        numadd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/list_add.png"))); // NOI18N
        numadd.setMargin(new java.awt.Insets(0, 0, 0, 0));
        numadd.setName("numadd"); // NOI18N
        numadd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addNumber(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(numadd, gridBagConstraints);

        jLabel3.setText("Collegamenti"); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jLabel3.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 1, 0);
        getContentPane().add(jLabel3, gridBagConstraints);

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        linksList.setName("linksList"); // NOI18N
        linksList.setPreferredSize(null);
        jScrollPane3.setViewportView(linksList);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(jScrollPane3, gridBagConstraints);

        assrem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/list_remove.png"))); // NOI18N
        assrem.setMargin(new java.awt.Insets(0, 0, 0, 0));
        assrem.setName("assrem"); // NOI18N
        assrem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                removeLink(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(assrem, gridBagConstraints);

        assadd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/list_add.png"))); // NOI18N
        assadd.setMargin(new java.awt.Insets(0, 0, 0, 0));
        assadd.setName("assadd"); // NOI18N
        assadd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addLink(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(assadd, gridBagConstraints);

        jLabel4.setText("Numeri"); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        jLabel4.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 1, 3);
        getContentPane().add(jLabel4, gridBagConstraints);

        jPanel2.setName("jPanel2"); // NOI18N

        confirmB.setText("Ok"); // NOI18N
        confirmB.setName("confirmB"); // NOI18N
        confirmB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                editDone(evt);
            }
        });
        jPanel2.add(confirmB);

        cancelB.setText("Annulla"); // NOI18N
        cancelB.setName("cancelB"); // NOI18N
        cancelB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                editCanceled(evt);
            }
        });
        jPanel2.add(cancelB);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        getContentPane().add(jPanel2, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

   /*
    * agggiunge una riga alla tabella dei numeri
    */
    private void addNumber(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addNumber
       nt.addRow();
    }//GEN-LAST:event_addNumber

   /*
    * elimina una riga dalla tabella dei numeri
    */
    private void delNumber(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delNumber
       int s = nt.getSelectedRow();
       if (s > -1) {
          nt.delRow(s);
       } else {
          nt.delRow(-1);
       }
    }//GEN-LAST:event_delNumber

   /*
    * Aggiunge un link alla linkList
    */
    private void addLink(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addLink
       DefaultListModel lmodel = (DefaultListModel) linksList.getModel();

       if (list == null) {
          return;
       }
       AgeEntry e = new SearchDiag(JOptionPane.getFrameForComponent(this), true, list).getSelection();

       if (e != null) {
          lmodel.addElement(e);
       }
    }//GEN-LAST:event_addLink

   /*
    * rimuove un link dalla lista dei
    */
    private void removeLink(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeLink
       DefaultListModel lmodel = (DefaultListModel) linksList.getModel();
       int selectedIndex = linksList.getSelectedIndex();

       if (selectedIndex > -1) {
          /*
           * se un elemento è selezionato rimuovilo
           */
          lmodel.remove(selectedIndex);
       } else {
          /*
           * altrimenti rimuovi l'ultimo
           */
          int n = lmodel.getSize();
          lmodel.remove(n - 1);
       }
    }//GEN-LAST:event_removeLink

   /*
    * Termina la modifica della voce di rubrica.
    *
    * termina la modifica e applica i cambiamenti
    */
    private void editDone(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editDone
       changeEntryType();//TODO ... e que?
       boolean ret = true;
       if (writeEnabled) {
          ret = applyChanges();
       }
       if (ret) {
          dispose();
       }
    }//GEN-LAST:event_editDone

   /*
    * Termina la modifica della voce di rubrica.
    *
    * termina la modifica e annulla i cambiamenti
    */
    private void editCanceled(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editCanceled
       entry = null;
       if (writeEnabled) {
          nomeTF.setText("");
          cognomeTF.setText("");
          descArea.setText("");
          emailTF.setText("");
          // elimina tutti i numeri
          nt.clear();
          // elimina tutti i link
          ((DefaultListModel) linksList.getModel()).clear();
       }
       dispose();
    }//GEN-LAST:event_editCanceled


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton assadd;
    private javax.swing.JButton assrem;
    private javax.swing.JRadioButton aziendajRadioButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton cancelB;
    private javax.swing.JLabel cognomeL;
    private javax.swing.JFormattedTextField cognomeTF;
    private javax.swing.JButton confirmB;
    private javax.swing.JTextArea descArea;
    private javax.swing.JFormattedTextField emailTF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList linksList;
    private javax.swing.JLabel nameL;
    private javax.swing.JFormattedTextField nomeTF;
    private javax.swing.JButton numadd;
    private javax.swing.JButton numrem;
    private javax.swing.JRadioButton personajRadioButton;
    // End of variables declaration//GEN-END:variables
}
